<?php if(isset($this->all_items)){?>
	<?php 
	
	global $jbconfig;
	
	$thisLink = str_replace(JPATH_ROOT, JURI::root(), dirname(__FILE__));
	$thisLink = str_replace(DS, "/", $thisLink)."/style.css";
	
	if( ! isset ($formName) )
		$formName = "adminForm";
	?>
	
	<?php $filter_order = JRequest::getVar('filter_order', $jbconfig['posts']->get('filter_order', 'a.id')); ?>
	<?php $filter_order_dir = JRequest::getVar('filter_order_Dir', $jbconfig['posts']->get('filter_order_Dir', 'desc'));?>
	<script type="text/javascript">
		var select_text = '<?php echo JText::_('jobs selected')?>';
		window.addEvent('domready', function() {        
            if( window.location.href.indexOf('#') > 0){
                document.adminForm.filter_order_2.value="a.is_hotjob";
            }
        });
	</script>
	<link rel="stylesheet" href="<?php echo $thisLink;?>" type="text/css" />
	
	<!-- BOX ACTION TOP -->
	<?php if (count($this->all_items)>0) {?>
	<div id="ja-box-action-top">
	<?php if(!isset($module)){?>
    <div class="ja-sortlist clearfix">
		<span><label for="filter_order_2"><?php echo JText::_('Sort By')?>:</label></span>
		<?php if(substr(trim($filter_order), 0, 2)=='a.') $filter_order = substr(trim($filter_order), 2)?>
		<select class="sortby" onchange="$('filter_order').value=this.value; doSearch('<?php echo $this->layout?>');" name="filter_order_2" id="filter_order_2">
		 	<option value="a.is_hotjob" <?php if($filter_order=='is_hotjob'){?>selected="selected"<?php }?>><?php echo JText::_('Featured Job')?></option>
			<option value="a.effected_date" <?php if($filter_order=='effected_date'){?>selected="selected"<?php }?>><?php echo JText::_('Date')?></option>
			<option value="a.id" <?php if($filter_order=='id'){?>selected="selected"<?php }?>><?php echo JText::_('Job ID')?></option>
			<option value="a.location_id" <?php if($filter_order=='location_id'){?>selected="selected"<?php }?>><?php echo JText::_('Location')?></option>
			<option value="a.title" <?php if($filter_order=='title'){?>selected="selected"<?php }?>><?php echo JText::_('Job Title')?></option>
			<option value="profi.company" <?php if($filter_order=='profi.company'){?>selected="selected"<?php }?>><?php echo JText::_('Company Name')?></option>
		</select>
		
		<select class="sortby" onchange="$('filter_order_Dir').value=this.value; doSearch('<?php echo $this->layout?>');" name="filter_order_Dir_2" id="filter_order_Dir_2">
			<option value="asc" <?php if($filter_order_dir=='asc'){?>selected="selected"<?php }?>><?php echo JText::_('ASC')?></option>
			<option value="desc" <?php if($filter_order_dir=='desc'){?>selected="selected"<?php }?>><?php echo JText::_('DESC')?></option>
		</select>
	</div>
	<?php }?>
    <input type="checkbox" name="toggle" value="" onclick="checkAlls(document.<?php echo $formName;?>, <?php echo count($this->all_items); ?>); updateselectalljobs('<?php echo $formName;?>', this,<?php echo count($this->all_items); ?>);" class="ja-selectall" />
    <input type="text" readonly="readonly" value="0 <?php echo JText::_("jobs selected");?>" id="selectedJobs<?php echo $formName;?>" name="selectedJobs<?php echo $formName;?>" class="ja-job-selected-number" />
    
		<a href="javascript:submitbutton_multi_view('multi_view', '<?php echo count($this->all_items); ?>', '<?php echo $formName;?>' )" class="button view">
			<span style="vertical-align: top !important;"><?php echo JText::_('View'); ?></span>
		</a>
		<?php if (getCurrentUserType() == JBEMPLOYER_USER  && JRequest::getVar("layout") == "myjobs" && JRequest::getVar("employerid", "") == "") { ?>
		<a href="javascript:submitbutton_multi_view('multi_delete','<?php echo count($this->all_items); ?>', '<?php echo $formName;?>')" class="button">
			<span style="vertical-align: top !important;"><?php echo JText::_('Delete'); ?></span>
		</a>
		<?php } ?>
	<?php if (getCurrentUserType() == JBJOB_SEEKER_USER) { ?>
		<a href="javascript:submitbuttonGeneral('multi_starred','<?php echo count($this->all_items); ?>', '<?php echo $formName;?>')" class="button">
			<span style="vertical-align: top !important;"><?php if (JRequest::getVar('layout')!='jajobseekerlist') echo JText::_('Favorite'); else echo JText::_('Remove favorite'); ?></span>
		</a>            
	<?php } ?>
	</div>
	<?php } 
		else 
		{
			if (JRequest::getVar('layout')=='job_list_via_profiles')
			echo "<span>".JText::_("Don't have any jobs")."</span>";
		}
	?>
	
	<!-- BOX ACTION TOP -->
	
	<!-- JA JOBLIST -->
	<div id="ja-joblist">
		<ol id="ja-searchjoblist">
			
			<?php
			
		  	$items = $this->all_items;
		  	$k = 0;
		  	$orderNo = 0;
		  	$currentTable = '';
		  	$max_length = $jbconfig['posts']->get('posts_description_chars')? $jbconfig['posts']->get('posts_description_chars'):150;
		  		  	
			$field_salary = null;
		  	if ( isset($this->allFields) ) {
    			for($ii = 0, $nn = count($this->allFields); $ii < $nn; $ii++ ){
    		  		$field = $this->allFields[$ii];
                    $field_name = $field->field_name;
                    if($field_name=='salary_range'){
                    	$field_salary = $field;
                    	break;
                    }               
    		  	}
		  	}
		  	
		  	for($i = 0, $n = count($this->all_items); $i < $n; $i++, $orderNo++)
		  	if (isset($items[$i]->id))
		  	{
		   		$item = $items[$i];
		   		JFilterOutput::objectHTMLSafe( $item, ENT_QUOTES, 'effected_date' );
		   		
		   		$currency = isset($item->currency)?$item->currency:$jbconfig['currency']->get('currency', '$');
		   		
		   		$temp_user = JFactory::getUser($item->user_id_tmp);
	    		$temp_user->username = str_replace('.','()',$temp_user->username);
		   		$class = '';		   		
		   		if($item->is_hotjob==1) $class = "premiumjob";
  	
				if(is_array($item->cat_id_tmp)) $cats = implode(',', $item->cat_id_tmp);
		   		else $cats = $item->cat_id_tmp;
				$cat_names = getCategories($cats);
				$cats = explode(',',$cat_names);


				if(is_array($item->location_id_tmp)) $locations = implode(',', $item->location_id_tmp);
		   		else $locations = $item->location_id_tmp;
		   		$location_names = getLocation($locations);
		   		$locations = explode(',',$location_names);
		   		?>   		
				<li onclick="" id="li_<?php echo $item->id; ?>" class="<?php echo $class?>  row<?php echo ($i%2); ?> <?php if ($i+1==$n): echo 'last'; endif;?>" onmouseover="$(this).addClass('hover')" onmouseout="$(this).removeClass('hover')"><div class="inner">
					
					<span class="ja-job-item-checkbox">
						<input title="<?php echo JText::_('Click here to view more jobs')?>" id="cb<?php echo $i?><?php echo $formName;?>" type="checkbox" onclick="isCheckedJob(document.<?php echo $formName;?>, this.checked); updateselectedjobs('<?php echo $formName;?>', this)" value="<?php echo $item->id; ?>" name="cid[]"/>
					</span>

					<?php if($jbconfig['posts']->get('postsshow_days_elapsed', 1) ) { ?>		 	
					<span class="datetime">(<?php echo $item->effected_date?>)</span>
					<?php } ?>
					
					 <?php if($item->is_hotjob) { ?>
							<span class="ja-featured-job">(<?php echo JText::_('Featured Job')?>)</span>
					 <?php } elseif(time()-strtotime($item->effected_date_tmp)<=24*60*60) { ?>
						<span class="ja-new-job">(<?php echo JText::_('New')?>)</span>
					<?php }?>
					
					<span class="ja-row-number">
	       			<?php if (isset($this->pagination)) { ?>
	       				<?php echo $i+1+$this->pagination->limitstart; ?>
	       			<?php }else{?>
	       				<?php echo $i+1; ?>
	       			<?php }?>
	       			</span>
       			
					
					<div class="ja-job-details">
						
						<!-- JOB TITLE -->
						<h3 class="ja-job-title">
							<?php $alias = JFilterOutput::stringURLSafe(trim($item->title));?>
							<a href="<?php echo JRoute::_( 'index.php?option='. JBCOMNAME .'&view=jajobs&layout=jaview&cid[]='.$item->id.'&alias='.$alias."&Itemid=".$this->Itemid); ?>"  class="<?php echo $class;?>">
								<?php echo $item->title; ?>
							</a>
							
						<!-- SALARY -->
			           		<?php if(isset($item->salary_range)){?>
			           		<span class="ja-job-salary">
			           			<?php if(isset($item->salary_min) && isset($item->salary_max) && ($item->salary_min || $item->salary_max)){?>                   					
			           				<?php echo $currency.$item->salary_min?> - <?php echo $currency.$item->salary_max?>
			           			<?php }elseif($field_salary){
			           					echo rendfield($item, $field_salary,false,true,true);	                   				
			           			} ?>	    
										</span>               			
			           		<?php }?>	
			           	<!-- //SALARY -->
									
		         		</h3>
		         		<!-- //JOB TITLE -->
              	
              	<?php 
					//Get Logo size
					if (!$item->logo)
					{
						$item->logo = JURI::base () . 'components/com_jajobboard/images/no-image.gif';
					}else $item->logo = JURI::root().$item->logo;
					
					$item->logo = str_replace( JURI::base(), "",  $item->logo);
					
					$logo_size = jaGetImageSize($item->logo);
					$logo_width = $logo_size['width'];
					$logo_height = $logo_size['height'];
					if ( strpos( $item->logo, JURI::base() ) === false )
						$item->logo = JURI::base().$item->logo;
					
				?> 	                       	
	            <div class="ja-job-description <?php if($item->logo) echo 'enhancedAd';?> clearfix">
	            <?php if($jbconfig['posts']->get('posts_show_posted_by', 1)){ ?>
	            <a href="<?php echo JRoute::_( 'index.php?option='. JBCOMNAME .'&view=japrofiles&layout=jaview&cid[]='.$temp_user->username."&profile_id=".$temp_user->username); ?>"  class="<?php echo $class;?>">
	            	<img src="<?php echo $item->logo?>" alt="<?php echo $item->company?>" class="logo" align="left" width="<?php echo $logo_width?>" height="<?php echo $logo_height?>"/>
	            </a>
	            <span class="ja-companyname">
	            <a href="<?php echo JRoute::_( 'index.php?option='. JBCOMNAME .'&view=japrofiles&layout=jaview&cid[]='.$temp_user->username."&profile_id=".$temp_user->username); ?>"  class="<?php echo $class;?>">
	            	<?php echo $item->company?>
	            </a>
	            </span>
	            <?php } ?>
					<?php 						
						if( $jbconfig['posts']->get('posts_show_description', 1) ){							
							$item->job_detail = htmlspecialchars_decode($item->job_detail);
							echo SmartTrim::trim($item->job_detail,0,$max_length);
						}
					?>
					
	         			<div class="ja-job-meta clearfix">
							<span class="ja-job-category">
		            			<?php if($cats && $jbconfig['posts']->get('posts_show_job_type', 1) ) { ?>
			            			<strong><?php echo JText::_('Category')?>:</strong>
									<?php foreach ($cats as $cat) { ?>
			            				<a href="<?php echo JRoute::_('index.php?option=com_jajobboard&view=jajobs&layout=filter_job_list&cat_id='.$cat)?>" title="<?php echo $cat?>"><?php echo $cat?></a> 
			            			<?php } ?>				            
			            		<?php } ?>
	          				</span>
	          
	          				<span class="ja-job-location">
								<strong><?php echo JText::_('Location')?>: </strong>							
								<?php foreach ($locations as $location) { ?>
		            				<a href="<?php echo JRoute::_('index.php?option=com_jajobboard&view=jajobs&layout=filter_job_list&location_id='.$location)?>" title="<?php echo $location?>"><?php echo $location?></a> 
		            			<?php } ?>	
							</span>
						</div>
				<div style="clear:both">
				<?php if (getCurrentUserType() == JBEMPLOYER_USER  && JRequest::getVar("layout") == "myjobs") { 
					$numApplications = JobBoardModelJAJobs::getNumApplications($item->id);
					if( $numApplications > 0 ){
					?>
				    <br/><strong style="font-size:120%"><?php echo JText::_("Applications");?></strong>: <a target="_blank" href="<?php echo JRoute::_('index.php?option=com_jajobboard&view=jaapplications&layout=jaempllist&job_id='.$item->id);?>"><?php echo $numApplications;?></a>
				<?php } else { 
					?>
					<br/><strong style="font-size:120%"><?php echo JText::_("Applications");?></strong>: <?php echo $numApplications;?>
					<?php				
				} } ?>
				<?php if ( JRequest::getVar("zipcode_distance", "") != "" ) { ?>
				    <br/><strong style="font-size:120%"><?php echo JText::_("Distance from zipcode: ".JRequest::getVar("zipcode_from", "")." is: " );?></strong> <?php echo $item->zipcode_distance ?> (miles)
				<?php } ?>
				</div>
				</div>
	                    
          	</div>
        	</div>           
        </li>
		            
		  <?php } ?>
	 	</ol>
	 </div>
	 <!-- //JA JOBLIST -->
<?php if (count($this->all_items)>0) {?>	 
	<div id="ja-box-action-bot" class="clearfix">
			
	  <input type="text" readonly="readonly" value="0 <?php echo JText::_("jobs selected");?>" id="selectedJobs2<?php echo $formName;?>" name="selectedJobs2<?php echo $formName;?>" class="ja-job-selected-number" />	
	  <a href="javascript:submitbutton_multi_view('multi_view', '<?php echo count($this->all_items); ?>', '<?php echo $formName;?>' )" class="button">
			<span style="vertical-align: top !important;"><?php echo JText::_('View'); ?></span>
		</a>      
		<?php if (getCurrentUserType() == JBJOB_SEEKER_USER) { ?>
		<a href="javascript:submitbutton('multi_starred','<?php echo count($this->all_items); ?>', '<?php echo $formName;?>')" class="button">
			<span style="vertical-align: top !important;"><?php if (JRequest::getVar('layout')!='jajobseekerlist') echo JText::_('Favorite'); else echo JText::_('Remove favorite'); ?></span>
		</a> 
		<?php } ?>
	</div>
	 
	 
	<?php if(isset($this->pagination)) {?>
		<div class="jobs-pagination clearfix">
			<div class="limit">
				<label for="limit"><?php echo JText::_("Display num")?></label>
				<?php echo $this->getListLimit(JRequest::getInt('limit', $jbconfig['posts']->get('display_num'))); ?>
			</div>
			
			<?php echo $this->pagination->getPagesLinks(); ?>
		</div>
	<?php } ?>
	
<?php 
		}  
	}
		
?>   


<?php if (!isset($jbconfig['feeds']) || $jbconfig['feeds']->get('show_feed', 1)) {?>
<div class="moduletable rsslink">
	<?php $Itemid_feed = get_Itemid(array('option'=>'com_jajobboard', 'view'=>'jafeeds'))?>
	<a href="<?php echo JRoute::_("index.php?option=com_jajobboard&view=jafeeds&layout=guide&Itemid=".$Itemid_feed); ?>"><?php echo JText::_('Jobs via RSS'); ?><img alt="RSS help" src="<?php echo JURI::root()."components/com_jajobboard/images/rss.gif"; ?>" /></a>
</div>	   
<?php } ?>
